/*
 * main implementation: use this sample to create your own application
 *
 */
#include <stdio.h>
#include "support_common.h" /* include peripheral declarations and more */
#include "gpio.h"
#include "pwm.h"
#include "song.h"
#include "note.h"
#include "pit.h"
#include "speaker.h"
#include "pushb.h"
#include "led.h"

int delay_flag=0;
int BPM;

int main(void)
{		
		int note_i=0;
		
        gpio_port_ta_init();
        speaker_init();
        uc_led_init();
        uc_led_all_off();
        pit0_init();
        song_init();
        Note delay_note = create_note(Pitch_00, Delay_60);
        BPM=delay_note.d;
        gpt_init();
        int i = 0;
        MCF_PIT0_PCSR |= 0x01; // PIT enabled
        while(1)
        	
        {	
        	if(delay_flag ==0)
        	{ 
        		if(i==3)
        		{
        			i=0;
        		}
        		play_JB();
        		uc_led_on(i);
        		delay_flag=2;
        		i++;
        	}
        	
        	else if(delay_flag ==1)
        	{
        		uc_led_off(i);
        		play_delay(delay_note);
        		delay_flag=3;
        	}
        		
        }

        return 0;
}

